# coding=utf-8
"""
Author: Mr.夏末
@Function: json字符串
"""
import json

# 什么是JSON字符串：字典数据结构的字符串体现
import re

ddd = {'a':'b',"c":1}
# 字典转为JSON字符串
dddstr = json.dumps(ddd)
print(type(dddstr))

res = r'''
jQuery1102017513081917021256_1658411291408({"Srcid":"5809","ResultCode":"0",
"status":"0","QueryID":"1886242454","Result":[{"DisplayData":{"strategy":
{"tempName":"ip","precharge":"0","ctplOrPhp":"1"},"resultData":{"tplData":
{"srcid":"5809","resourceid":"5809","OriginQuery":"1.1.1.1","origipquery":"1.1.1.1",
"query":"1.1.1.1","origip":"1.1.1.1","location":"\u6cdb\u64ad Cloudflare","userip":"",
"showlamp":"1","tplt":"ip","titlecont":"IP\u5730\u5740\u67e5\u8be2","realurl":
"http:\/\/www.ip138.com\/","showLikeShare":"1","shareImage":"1","data_source":"AE"},
"extData":{"tplt":"ip","resourceid":"5809","OriginQuery":"1.1.1.1"}}},
"ResultURL":"http:\/\/www.ip138.com\/","Weight":"2","Sort":"1","SrcID":
"5809","ClickNeed":"0","SubResult":[],"SubResNum":"0","ar_passthrough":[],
"RecoverCacheTime":"0"}],"data":[{"srcid":"5809","resourceid":"5809",
"OriginQuery":"1.1.1.1","origipquery":"1.1.1.1","query":"1.1.1.1",
"origip":"1.1.1.1","location":"\u6cdb\u64ad Cloudflare","userip":"",
"showlamp":"1","tplt":"ip","titlecont":"IP\u5730\u5740\u67e5\u8be2",
"realurl":"http:\/\/www.ip138.com\/","showLikeShare":"1","shareImage":"1"}],"ResultNum":"1"})
'''

# 怎么得到标准的JSON字符串？字符串截取
# 怎么得到字符串里面某一个字符的下标
# 从左边找第一个大括号的下标
l_index = res.find("{")
print(l_index)
# 从末尾找第一个大括号的下标
r_index = res.rfind("}")
print(r_index)

# 怎么去掉换行？
res = res.replace('\n',' ')

res = res[l_index:r_index+1]
print(res)
print("-----------------------------------------------------")
# 怎么转为字典？JSON字符串转为字典
res_dict = json.loads(res)
print(res_dict)

s = "订单号：202207192221383736  | 付款金额（元）：4776.00 元"
res = re.findall(r"\d{18}|\d+\.\d{2}",s)
print(res)